﻿@using SelfMadeMillionaire.Core.Entities
@model YahooFinanceWatcher.Models.SymbolOptionsHistoryModel
@{
    ViewBag.Title = "Yahoo Finance Watcher";
    Layout = "~/Views/Shared/_MainLayout.cshtml";
}

<div class="row admin_wrapper">
	<div class="col-sm-12 col-md-12 col-lg-12" style="margin-top:10px;">
        <div class="div_group" style = "margin-top:10px;">
            @using (Html.BeginForm("Filter", "SymbolOptionsHistory", FormMethod.Post, new { @class = "form-horizontal", id = "formFilter", style = "margin-top:20px;" }))
            {
				@Html.ValidationSummary()
                @Html.HiddenFor(model => model.SortOrder)

                <div class="row">
                    <div class="col-sm-3">
				        <div class="form-group">
					        @Html.LabelFor(model => model.DaysInTradeFilter, new { @class = "col-sm-8 control-label" })
					        <div class="col-sm-4">
						        @Html.TextBoxFor(m => m.DaysInTradeFilter, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.DaysInTradeFilter)
					        </div>
				        </div>
			        </div>
                    <div class="col-sm-3">
				        <div class="form-group">
					        @Html.LabelFor(model => model.MinDiscountFilter, new { @class = "col-sm-8 control-label" })
					        <div class="col-sm-4">
						        @Html.TextBoxFor(m => m.MinDiscountFilter, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.MinDiscountFilter)
					        </div>
				        </div>
			        </div>
		        </div>
                
                <div class="row">
                    <div class="col-sm-3">
				        <div class="form-group">
					        @Html.LabelFor(model => model.MinAnnualReturnFieldFilter, new { @class = "col-sm-8 control-label" })
					        <div class="col-sm-4">
						        @Html.DropDownListFor(m => m.MinAnnualReturnFieldFilter, Model.MinAnnualReturnFieldList, new { @class = "form-control" })
					        </div>
				        </div>
			        </div>
                    <div class="col-sm-1">
                        <div class="col-sm-12">
						    @Html.TextBoxFor(m => m.MinAnnualReturnFilter, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.MinAnnualReturnFilter)
                        </div>
                    </div>
		        </div>
                
                <div class="row">
                    <div class="col-sm-3">
				        <div class="form-group">
					        @Html.LabelFor(model => model.MinProbabilityFilter, new { @class = "col-sm-8 control-label" })
					        <div class="col-sm-4">
						        @Html.TextBoxFor(m => m.MinProbabilityFilter, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.MinProbabilityFilter)
					        </div>
				        </div>
			        </div>
                    <div class="col-sm-2">
                        <label class="radio-inline custom_check_radiobox">
                            @Html.RadioButtonFor(m => m.IsCallsFilter, true, new { name = "IsCallFilter", id = "IsCallsFilter" }) Calls
                        </label>
                        <label class="radio-inline custom_check_radiobox">
                            @Html.RadioButtonFor(m => m.IsCallsFilter, false, new { name = "IsCallFilter" }) Puts
                        </label>
                        
                    </div>

                    <div class="col-sm-2">
        		        <button type="submit" id="btnFindHistory" class="btn btn-default">Search</button>
			        </div>
                </div>
            }
        </div>

        <div class="div_group" style = "margin-top:10px;">
            <div class="page-header" style="margin-top:10px;">
                <b>@(Model.IsCallsFilter?"Calls":"Puts")</b>
            </div>

		    <div class="table_container">
		        <div id="divSymbolOptionsHistoryList">
			        @Html.Partial("SymbolOptionsHistoryList", Model)
			    </div>
		    </div>
        </div>

    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnFindHistory").click(function (e) {
            e.preventDefault();
            RefreshList();
        });
    });

    function RefreshList() {
        if ($('#formFilter').valid()) {
            $.get("@Url.Action("Index")",
                    {
                        IsCallsFilter: $('#IsCallsFilter').is(':checked'),
                        DaysInTradeFilter: $("#@Html.IdFor(m => m.DaysInTradeFilter)").val(),
                        MinDiscountFilter: $("#@Html.IdFor(m => m.MinDiscountFilter)").val(),
                        MinAnnualReturnFieldFilter: $("#@Html.IdFor(m => m.MinAnnualReturnFieldFilter)").val(),
                        MinAnnualReturnFilter: $("#@Html.IdFor(m => m.MinAnnualReturnFilter)").val(),
                        MinProbabilityFilter: $("#@Html.IdFor(m => m.MinProbabilityFilter)").val(),
                        SortOrder: $("#@Html.IdFor(m => m.SortOrder)").val()
                    },
                    function (result) {
                        $("#divSymbolOptionsHistoryList").html(result);
                    });
        }
    }
</script>

